import { observable, action, toJS } from 'mobx';
import { WeaLocaleProvider } from 'ecCom';


const getLabel = WeaLocaleProvider.getLabel;


/** ***  路径、搜索栏相关  **** */

class PathSearch {
   constructor(parent) {
      this.parent = parent;
   }

   @observable home = '';
   @observable path = [];
   @observable searchValue = '';
   @observable homeTab = '云盘';


   // 修改 pathSearchData 数据统一接口  todo【路径发生变化，重新调 API 请求数据】
   @action setPathSearchData = (newData = {}) => {
      Object.keys(newData).forEach((i) => {
         this[i] = newData[i];
      });
      newData.hasOwnProperty('path') && this.parent.fileSystem.clearSelection(); // 如果路径发生变化，清空选中
      // todo 在API回调里，将新data与粘贴板的 ctrlX 属性作对比，如果为 如果为true务必更新到data里
   };
   // 更改homeTab
   @action updatePathHomTab = () => {
      const topKey = this.parent.topSelectedKey;
      if (topKey === 'netDisk') {
         this.homeTab = '云盘';
      } else if (topKey === 'share') {
         this.parent.shareTabSelectedKey === 'myShare' && (this.homeTab = '我的分享');
         this.parent.shareTabSelectedKey === 'colleagueShare' && (this.homeTab = '同事的分享');
      }
   };
}


export default PathSearch;
